package com.xinwangai.jingbai.service.impl;

import com.xinwangai.jingbai.mapper.DictionaryMapper;
import com.xinwangai.jingbai.pojo.BO.DictionaryBO;
import com.xinwangai.jingbai.pojo.DTO.DictionaryDTO;
import com.xinwangai.jingbai.pojo.VO.DictionaryVO;
import com.xinwangai.jingbai.pojo.VO.DictionaryTypeVO;
import com.xinwangai.jingbai.service.DictionaryService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 字典服务实现类
 *
 * @author guo.wenliang
 * @since 2025/1/15
 */
@Service
public class DictionaryServiceImpl implements DictionaryService {

    private final DictionaryMapper dictionaryMapper;

    public DictionaryServiceImpl(DictionaryMapper dictionaryMapper) {
        this.dictionaryMapper = dictionaryMapper;
    }

    // ========== 字典表类型查询（只读） ==========

    @Override
    public List<DictionaryTypeVO> getDictionaryTypes() {
        return dictionaryMapper.getDictionaryTypes();
    }

    // ========== 字典数据管理 ==========

    @Override
    public boolean addDictionary(DictionaryDTO dictionaryDTO) {
        DictionaryBO dictionaryBO = new DictionaryBO();
        BeanUtils.copyProperties(dictionaryDTO, dictionaryBO);
        return dictionaryMapper.insertDictionary(dictionaryBO) > 0;
    }

    @Override
    public boolean updateDictionary(DictionaryDTO dictionaryDTO) {
        DictionaryBO dictionaryBO = new DictionaryBO();
        BeanUtils.copyProperties(dictionaryDTO, dictionaryBO);
        return dictionaryMapper.updateDictionary(dictionaryBO) > 0;
    }

    @Override
    public DictionaryVO getDictionaryById(Long id) {
        return dictionaryMapper.getDictionaryById(id);
    }

    @Override
    public List<DictionaryVO> getDictionaryList(DictionaryDTO dictionaryDTO) {
        return dictionaryMapper.getDictionaryList(dictionaryDTO);
    }

    @Override
    public List<DictionaryVO> getDictionaryByType(String dictType, String status) {
        return dictionaryMapper.getDictionaryByType(dictType, status);
    }
}